package com.woniuxy.woniuhis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.woniuhis.entity.SurgeryBooking;
import com.woniuxy.woniuhis.entity.SurgeryRoom;
import com.woniuxy.woniuhis.exception.SurgeryRoomServiceException;
import com.woniuxy.woniuhis.mapper.SurgeryBookingMapper;
import com.woniuxy.woniuhis.mapper.SurgeryRoomMapper;
import com.woniuxy.woniuhis.service.SurgeryRoomService;

@Service
public class SurgeryRoomServiceImpl implements SurgeryRoomService {
	
	@Autowired
	SurgeryRoomMapper surgeryRoomMapper;
	
	@Autowired
	SurgeryBookingMapper surgeryBookingMapper;
	/**
	 * 	添加手术室
	 */
	@Override
	public void addSurgeryRoom(SurgeryRoom surgeryRoom) {
		try {
			surgeryRoomMapper.insertSurgeryRoom(surgeryRoom);			
		} catch (Exception e) {
			e.printStackTrace();
			throw new SurgeryRoomServiceException("系统维护中");
		}
	}
	
	/**
	 * 	更新手术室
	 */
	@Override
	public void modifySurgeryRoom(SurgeryRoom surgeryRoom) {
		try {
			surgeryRoomMapper.updateSurgeryRoom(surgeryRoom);			
		} catch (Exception e) {
			e.printStackTrace();
			throw new SurgeryRoomServiceException("系统维护中");
		}
	}
	
	/**
	 * 	查询指定手术室
	 */
	@Override
	public SurgeryRoom findSurgeryRoomById(String id) {
		try {
			return surgeryRoomMapper.selectSurgeryRoomById(id);			
		} catch (Exception e) {
			e.printStackTrace();
			throw new SurgeryRoomServiceException("系统维护中");
		}
	}
	
	/**
	 * 	查询所有的手术室
	 */
	@Override
	public List<SurgeryRoom> findAllSurgeryRooms(SurgeryRoom surgeryRoom) {
		try {
			return surgeryRoomMapper.selectSurgeryRooms(surgeryRoom);			
		} catch (Exception e) {
			e.printStackTrace();
			throw new SurgeryRoomServiceException("系统维护中");
		}
	}
	
	/**
	 * 	查询所有符合条件的手术室，分页查询
	 */
	@Override
	public PageInfo<SurgeryRoom> findSurgeryRooms(SurgeryRoom surgeryRoom,int pageIndex,int pageSize) {
		try {
			PageHelper.startPage(pageIndex, pageSize);
			List<SurgeryRoom> surgeryRooms = surgeryRoomMapper.selectSurgeryRooms(surgeryRoom);
			PageInfo<SurgeryRoom> pageInfo = new PageInfo<SurgeryRoom>(surgeryRooms);
			return pageInfo;
		} catch (Exception e) {
			e.printStackTrace();
			throw new SurgeryRoomServiceException("系统维护中");
		}
		
	}	

}